package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.api.BlackListApi;
import com.tanhua.db.mapper.BlackListMapper;
import com.tanhua.model.pojo.BlackList;
import com.tanhua.model.pojo.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {


    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public Page findByUserId(Long userId, Integer page, Integer pageSize) {
        //1.创建分页对象
        Page<UserInfo> pages = new Page<>(page,pageSize);

        //2.构建条件查询（此时需要创建BlackListMapper，用来通过条件进行查询数据）
        pages = blackListMapper.findByUserId(pages,userId);

        return pages;
    }

    @Override
    public void deleteBlack(Long userId, Long blackUserId) {
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId,userId);
        queryWrapper.eq(BlackList::getBlackUserId,blackUserId);
        blackListMapper.delete(queryWrapper);
    }
}
